import request from '@/utils/request/req';

// 消息数据类型定义
interface MessageData {
  type: string;
  data: string;
}

// 精准群发任务类型定义
interface PrecisionMessagingTask {
  taskId?: string;
  taskName: string;
  type: string;
  sendWxIds: string;
  sendGroupIds: string;
  dateTime: string;
  wxId: string;
  messageData: MessageData[];
}

// 查询参数类型定义
interface QueryParams {
  taskName?: string;
  type?: string;
  dateTime?: string;
  sendWxIds?: string;
  sendGroupIds?: string;
  wxId?: string;
}

// 删除精准群发列表
export function deletePrecisionMessaging(taskId: string) {
  return request({
    url: '/msg/deletePrecisionMessaging',
    method: 'get',
    params: { taskId }
  });
}

// 修改精准群发列表
export function updatePrecisionMessaging(data: PrecisionMessagingTask) {
  return request({
    url: '/msg/updatePrecisionMessaging',
    method: 'post',
    data
  });
}

// 新增精准群发列表
export function addPrecisionMessaging(data: PrecisionMessagingTask) {
  return request({
    url: '/msg/addPrecisionMessaging',
    method: 'post',
    data
  });
}

// 查找精准群发列表
export function selectPrecisionMessaging(params: QueryParams) {
  return request({
    url: '/msg/selectPrecisionMessaging',
    method: 'get',
    params
  });
}

// 上传图片
export function uploadFile(file: File) {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: '/file/Upload',
    method: 'POST',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}
